<%--

<!--------------------------------------------------------------------------------------------------------------------------------
 - Copyright 2007 CORE Solutions Limited
 - All rights reserved.
 - PROPRIETARY AND CONFIDENTIAL INFORMATION.
 - Use is subject to license terms.
 -
 - FUNCTION ID      :   CATALOG_DTL_TEMPLATE
 - AUTHOR           :   Craig Chun 
 - DATE CREATE      :   2007/07/20
 - DESCRIPTION      :   a PAGE-EDIT CONTENT JSP file for the function, CATALOG_DTL_TEMPLATE
 -                  :   
 -                  :   
 -                  :   
 -
 - MODIFICATION HISTORY:
 - DATE         AUTHOR          VERSION NO.         COMMENT
 - -----------  --------------  ------------------  -------------------
 - 2007/07/20   Craig Chun      1.0                 source is generated.
 -
 -
 -
--------------------------------------------------------------------------------------------------------------------------------->

--%>
<%@ include file="/jsp/com/erp/app/common/jsp/directives_include.jsp"%>

<%@ page  import="com.erp.app.setup.itemDetailTemplate.web.CatalogDtlTemplateAction" %>
<%@ page  import="com.erp.app.setup.itemDetailTemplate.web.CatalogDtlTemplateRow" %>

<%@ include file="/jsp/com/erp/app/common/jsp/html_include.jsp"%>

<jsp:useBean id="catalogDtlTemplateForm" scope="session" type="com.erp.app.setup.itemDetailTemplate.web.CatalogDtlTemplateForm" />

<%
ArrayList catalogDtlTemplateList = catalogDtlTemplateForm.getMultiRows();
pageContext.setAttribute("catalogDtlTemplateList", catalogDtlTemplateList);
rowReadOnly = false;
TableSchema ts = catalogDtlTemplateForm.getTs();
%>

<script language="javascript">

	function doLoad() {
		<%
		if (CommonUtil.nullToString((String)session.getAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE)).equals(ProjectConstants.GENERIC_YES)) {
			session.removeAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE);
			out.println("alert('Records saved.');");
		}
		if (ProjectConstants.GENERIC_YES.equals((String) session.getAttribute(ProjectConstants.SESSION_ALERT_AFTER_ADD_ITEM_DETAIL))){
			session.removeAttribute(ProjectConstants.SESSION_ALERT_AFTER_ADD_ITEM_DETAIL);
			String alMsg = (String) session.getAttribute(ProjectConstants.SESSION_CATEGORY_DETAIL_ALREADY_EXISTS_ITEMS);
			session.removeAttribute(ProjectConstants.SESSION_CATEGORY_DETAIL_ALREADY_EXISTS_ITEMS);
			out.println("alert('" + alMsg + " are not added, cause they are already exists');");
		}
		%>
				
		<%
		String lastAction = CommonUtil.nullToString(catalogDtlTemplateForm.getPageEvent());

		if (lastAction.startsWith(ProjectConstants.ACTION_SPEDIT)) {
			out.println(WebUtil.openSelectRemarkTextDo());
		}else if (lastAction.equalsIgnoreCase(CatalogDtlTemplateAction.ACTION_ADD_DTL_ROW)) {
			out.println(WebUtil.openSearchDo());
		}
		%>
	}
	
	function doCheckColumn(callIdx) {
		var count1 = 0;
		var count2 = 0;
		
		var isDel = document.getElementsByName("isSelected");
		var browser = document.getElementsByName("hdrBrowserColumn");
		var name = document.getElementsByName("itemDetailType");
		var callV = browser[callIdx].value;
		for(var i = 0; i<name.length; i++){


			if(isDel[i].value != ""){
			continue;
			}
            if (browser[i].value  == "1" )
			{
				count1++;
			}else if(browser[i].value  == "2" )
			{
				count2++;
			}
		}
		if(count1 > 1 && callV == "1" )
		{
           alert('There must be one and only one Item Detail can be shown in Catalog Content');
		}
		if(count2 > 1 && callV == "2" )
		{
           alert('There must be one and only one Item Detail can be shown in Catalog Description');
		}
	}

</script>

<body onLoad="javascript:doLoad();autofill_init();">
<html:form action="/catalogDtlTemplate">

<html:hidden property="pageEvent"/>
<html:hidden property="pageEventSrc"/>

<html:hidden property="pageMode"/>
<html:hidden property="deleteIdx"/>

<table class="table_top">

<tr>
	<td>
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_EXIT%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_SEARCH%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_CLEAR%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_ADD_DTL_ROW%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_SAVE%>"
			styleClass="button1"/>
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_REFRESH%>"
			styleClass="button1"/>
		<!--Print in English or Chinese? Uncomment where appropriate.-->
		<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_BACK%>"
			styleClass="button1"/>
		<!--<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_PRINT_ENG%>"
			styleClass="button1"/>-->
		<!--<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_PRINT_CHN%>"
			styleClass="button1"/>-->
	</td>
</tr>

<tr>
	<td>

		<table class="table_crit_short">
		<tr>
			<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_NODE_ID");
			%>
			<td class="col_label">
			<%=webLabel%>
			</td>
			<td class="col_value">
				<bean:write name="catalogDtlTemplateForm" property="srchNodeIdFr" filter="true"/> - 
				<% where = " NODE_ID = " + catalogDtlTemplateForm.getSrchNodeIdFr();%>
				<chtml:desc table="t_catalog"
					column="DESCRIPTION"
					where="<%=where%>"
				/>
			</td>
		</tr>
		<tr>
			<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_ITEM_DETAIL_TYPE");
			%>
			<td class="col_label">
			<%=webLabel%>
			</td>
			<td class="col_value">
				 <%
				       where=" COMPANY_CODE = '"+WebUtil.getAppropriateCompanyCode(session, null) + "' and REF_MASTER_CODE = '"+ ProjectConstants.CD_CATALOG_DTL_TYPE + "'";
					%>
					<select name="srchitemDetailType" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
					<option value="" />
					   <chtml:options table="t_code_dtl"
							valuecolumn="REF_CODE"
							textcolumn="REF_DESC"
							where="<%=where%>"
							order="seq, ref_desc"
							selected="<%=catalogDtlTemplateForm.getSrchitemDetailType()%>" />
					</select>
			</td>
		</tr>
		<tr>
			<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_STATUS");
			%>
			<td class="col_label">
			<%=webLabel%>
			</td>
			<td class="col_value" colspan="2">
				<%
			          where =" TYPE = '"+ ProjectConstants.CONSTANT_TYPE_ACT_INACT + "'";
					%>
					<select name="srchHdrStatus" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
					<option value="" />
					        <chtml:options table="T_SYS_CONSTANTS"
							valuecolumn="CONSTANT_CODE"
							textcolumn="CONSTANT_NAME"
							where="<%=where%>"					
							selected="<%=catalogDtlTemplateForm.getSrchHdrStatus()%>" />
					</select>
			</td>
		</tr>
		<tr>
			<%
			webLabel = ts.getDisplayWebLabelWithColonByObjectId("LBL_SRCH_ITEM_DETAIL_NAME");
			%>
			<td class="col_label">
			<%=webLabel%>
			</td>
			<td class="col_value">
				<html:text property="srchitemDetailName" styleClass="textbox1" maxlength="<%=colSize%>" size="<%=displaySize%>" />
			</td>
		</tr>		


		</table>

	</td>
</tr>

<tr>
	<td><font color='red'><html:errors/></font></td>
</tr>

<tr>
	<td class="grid_page">
	<%if(catalogDtlTemplateForm.getTotalPage() == 0 ) { %>
		&nbsp;
	<%} else { %>
		<input type="button" value="Go" class="button1" onClick="javascript:doSubmit('<%=catalogDtlTemplateForm.ACTION_SCROLL_TO%>');" >
		Page
		<html:text property="scrollTo" styleClass="textbox1" readonly="<%=rowReadOnly%>" maxlength="4" size="4" value="<%=String.valueOf(catalogDtlTemplateForm.getCurrentPage())%>"/>
		of <%=catalogDtlTemplateForm.getTotalPage()%>
	<%} %>
		<input type="button" value="|&lt;&lt;" class="button1" onClick="javascript:doSubmit('<%=catalogDtlTemplateForm.ACTION_SCROLL_TO_FIRST_PAGE%>');" <%=catalogDtlTemplateForm.getSidx() == 0 ? "disabled" : ""%>>
		<input type="button" value="&lt;&lt;" class="button1" onClick="javascript:doSubmit('<%=catalogDtlTemplateForm.ACTION_SCROLL_LEFT%>');" <%=catalogDtlTemplateForm.getSidx() == 0 ? "disabled" : ""%>>
		<input type="button" value="&gt;&gt;" class="button1" onClick="javascript:doSubmit('<%=catalogDtlTemplateForm.ACTION_SCROLL_RIGHT%>');" <%=catalogDtlTemplateForm.getSidx() < Integer.parseInt(catalogDtlTemplateForm.getLastPageSidx()) ? "" : "disabled"%>>
		<input type="button" value="&gt;&gt|" class="button1" onClick="javascript:doSubmit('<%=catalogDtlTemplateForm.ACTION_SCROLL_TO_LAST_PAGE%>');" <%=catalogDtlTemplateForm.getSidx() < Integer.parseInt(catalogDtlTemplateForm.getLastPageSidx()) ? "" : "disabled"%>>
	</td>
</tr>

</table>


<table class="table_grid">

	<tr class="grid_header">
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_DELETE");
		%>
		<td class="grid_header_col_narrow" nowrap>
			<%=webLabel%>
		</td>
	<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_SRCH_ITEM_DETAIL_NAME");
		%>
		<td  nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_SRCH_ITEM_DETAIL_TYPE");
		%>
		<td  nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_SEQ");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_STATUS");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
		<%
			webLabel = ts.getDisplayWebLabelByObjectId("LBL_GRID_BROWSER_COLUMN");
		%>
		<td class="grid_header_col" nowrap>
			<%=webLabel%>
		</td>
	</tr>

	<logic:iterate id="catalogDtlTemplateRow" name="catalogDtlTemplateList" indexId="idx" length="<%=String.valueOf(ProjectConstants.MAX_DISPLAY)%>" offset="<%=String.valueOf(catalogDtlTemplateForm.getSidx())%>">

	<%
		CatalogDtlTemplateRow row = (CatalogDtlTemplateRow) catalogDtlTemplateRow;
	%>

	<% if((row != null) && (CommonUtil.isEmpty(row.getIsDelete()))) {%>

	<tr <%=(idx.intValue()%2 == 0)? "class='grid_result1'": "class='grid_result2'"%>>
		<td nowrap>
			<chtml:button form="catalogDtlTemplateForm" pageEvent="<%=CatalogDtlTemplateAction.ACTION_DELETE_ROW%>" pageEventSrc="<%=String.valueOf(idx)%>" styleClass="button1" disabled="<%=String.valueOf(rowReadOnly)%>"/>
			<%--
			<input type=\"checkbox\" name=\"isDelete\" value=\"\" class=checkbox1 <%=rowReadOnly ? "disabled=\"true\"" : ""%> >
			--%>
		</td>
		<td nowrap>
			 <bean:write name="catalogDtlTemplateRow" property="itemDetailName" filter="true"/>&nbsp;
		<html:hidden property="itemDetailName" value="<%=CommonUtil.nullToString(row.getItemDetailName())%>"/>
		</td>
		<td nowrap>
			<bean:write name="catalogDtlTemplateRow" property="itemDetailType" filter="true"/>&nbsp;
			<html:hidden property="itemDetailType" value="<%=CommonUtil.nullToString(row.getItemDetailType())%>"/>
		</td>
		<td nowrap>
			<%
			colSize = String.valueOf(ts.getColSizeByObjectId("LBL_GRID_SEQ"));
			displaySize = String.valueOf(ts.getDisplaySizeByObjectId("LBL_GRID_SEQ"));
			%>
			<html:text property="hdrSeq" styleClass="textbox1" readonly="<%=rowReadOnly%>" maxlength="<%=colSize%>" size="<%=displaySize%>" value="<%=CommonUtil.nullToString(row.getHdrSeq())%>"/>
		</td>
		<td nowrap>
			 <%
			          where =" TYPE = '"+ ProjectConstants.CONSTANT_TYPE_ACT_INACT + "'";
					%>
					<select name="hdrStatus" <%=formReadOnly ? "disabled=\"true\"" : ""%> class="selectBox1">
					<option value="" />
					    <chtml:options table="T_SYS_CONSTANTS"
							valuecolumn="CONSTANT_CODE"
							textcolumn="CONSTANT_NAME"
							where="<%=where%>"					
							selected="<%=row.getHdrStatus()%>" />
					</select>
		</td>
		<td nowrap>
				<%
			          where =" ref_master_code = '"+ ProjectConstants.CD_CATALOG_BOWSER_DISPLAY_COL + "' and COMPANY_CODE = '" + WebUtil.getAppropriateCompanyCode(session, null) + "' ";
			 %>
			<select name="hdrBrowserColumn" <%=formReadOnly ? "disabled=\"true\"" : "" %> class="selectBox1"
					onchange="javascript:doCheckColumn('<%=idx%>');" >
					<option value="" />
					        <chtml:options table="t_code_dtl"
									valuecolumn="ref_code"
									textcolumn="ref_desc"
									where="<%=where%>"
									order="seq, ref_desc"
							selected="<%=row.getHdrBrowserColumn()%>" />
					</select>
		</td>
	</tr>
 <html:hidden property="isSelected" value="<%=row.getIsDelete()%>"/> 
	<% } else{// end if(row != null) %>
			<html:hidden property="isSelected" value="<%=row.getIsDelete()%>"/>
	  	<html:hidden property="isDelete" value="<%=row.getIdx()%>"/>
      <html:hidden property="hdrBrowserColumn"  value="<%=row.getHdrBrowserColumn()%>"/>
      <html:hidden property="hdrStatus"  value="<%=row.getHdrStatus()%>"/>
      <html:hidden property="hdrSeq"  value="<%=row.getHdrSeq()%>"/>
	  	<html:hidden property="itemDetailType" value="<%=CommonUtil.nullToString(row.getItemDetailType())%>"/>
	  	<html:hidden property="itemDetailName" value="<%=CommonUtil.nullToString(row.getItemDetailName())%>"/>
   <%}%>

	<html:hidden property="idx" value="<%=row.getIdx()%>" />
	<html:hidden property="rowMode"  value="<%=row.getRowMode()%>"/>

	</logic:iterate>

</table>

</html:form>
